<?
class SmartPayments
{
  var $url = "";
  var $verbose = false;
    
  function SmartPayments() 
  {
    //"https://www.tpisoft.com/SmartPayments/Transact.asmx";
    //https://payments.abanco.com/SmartPayments/transact2.asmx

    //$this->url = "https://payments.abanco.com/SmartPayments/transact2.asmx";
    $this->url = "https://payments.cynergydata.com/SmartPayments/transact2.asmx";
  }

  function prepareCCNumber($CCNumber)
  {
      $res_CCNumber = str_replace("-","",$CCNumber);	
	  $res_CCNumber = str_replace(" ","",$res_CCNumber);	      
      return $res_CCNumber;
  }
  
    /**
     * Process ePayment Credit Card Transaction. Valid input values are:
     * UserName & Password - Assigned by the payment gateway, <BR>TransType
     * - Auth | Sale | Return | Void | Force | Capture | RepeatSale | CaptureAll,
     * <BR>CardNum - Payment Card Number, ExpDate - Payment Card Expiration
     * Date in MMYY format, <BR>MagData - Payment Card Track II Mag-Stripe
     * Data, NameOnCard - Cardholders Name, Amount - Amount in DDDDD.CC format,
     * <BR>InvNum - Invoice Tracking Number, PNRef - Reference Number Assigned
     * by the payment gateway, <BR>Zip - CardHolder's billing ZipCode used
     * with AVS,  <BR>Street - CardHolder's billing Street Address used with
     * AVS,  <BR>CVNum - CardHolder's Card Verification Number used with
     * CV Check, <BR>ExtData - Extended Data in XML, Valid Values are: CustomerID<BR>AuthCode
     * - Original Authorization Code, <BR>CustCode - Customer Code used with
     * Commercial Cards, <BR>TipAmt - Tip Amount <BR>TaxAmt - Tax Amount
     * used with Commercial Cards, <BR>SequenceNum - Sequence Number used
     * with Recurring Transactions, <BR>SequenceCount - Sequene Count used
     * with Recurring Transactions, <BR>ServerID - Server ID, <BR>Timeout
     * - Timeout Value in Seconds (default=40), <BR>TrainingMode - Training
     * Mode T or F, <BR>Force - Force Duplicates T or F, <BR>RegisterNum
     * - Register Number, <BR>PONum - Purhcase Order Number, <BR>City - the
     * City of the CardHolder's billing address<BR>
     */
  function &processCreditCard($UserName,$Password,$TransType,$CardNum,$ExpDate,$MagData,$NameOnCard,$Amount,$InvNum,$PNRef,$Zip,$Street,$CVNum,$ExtData)
  {
       
       $sb = "UserName=".urlencode($UserName).
             "&Password=".urlencode($Password).
             "&TransType=".urlencode($TransType).
       		 "&ExtData=".urlencode($ExtData).
             "&CardNum=".urlencode($this->prepareCCNumber($CardNum)).
       		 "&CVNum=".urlencode($CVNum).
             "&ExpDate=".urlencode($ExpDate).
             "&MagData=".urlencode($MagData).
             "&NameOnCard=".urlencode($NameOnCard).
             "&Amount=".urlencode($Amount).
             "&InvNum=".urlencode($InvNum).
             "&PNRef=".urlencode($PNRef).
             "&Zip=".urlencode($Zip).                          
       		 "&Street=".urlencode($Street);
             
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/ProcessCreditCard",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
  }

/**
 * Process ePayment Debit Card Transactions. Valid input values are:
 * UserName & Password - Assigned by the payment gateway, <BR>TransType
 * - Auth | Sale | Return | Force | Capture |  CaptureAll, <BR>CardNum
 * - Payment Card Number, ExpDate - Payment Card Expiration Date in MMYY
 * format, <BR>MagData - Payment Card Track II Mag-Stripe Data, NameOnCard
 * - Cardholders Name, Amount - Amount in DDDDD.CC format, <BR>Pin -
 * Pin Block Returned by Pin-Pad, <BR>RegisterNum - Register Number Pin-Pad
 * is Connected, <BR>SureChargeAmt - Sure Charge Amount in DDDDD.CC format,
 * <BR>CashBackAmt - Cash Back Amount in DDDDD.CC format, <BR>ExtData
 * - Extended Data in XML, Valid Values are: <BR>Timeout - Timeout Value
 * in Seconds (default=40), <BR>TrainingMode - Training Mode T or F,
 * <BR>KeySerialNumber - Key Serial Number for DUKPT<BR>
 */
  function &processDebitCard($UserName,$Password,$TransType,$CardNum,$ExpDate,$MagData,$NameOnCard,$Amount,$InvNum,$PNRef,$Pin,$RegisterNum,$SureChargeAmt,$CashBackAmt,$ExtData)
  {
       $sb = "UserName=".urlencode($UserName).
             "&Password=".urlencode($Password).
             "&TransType=".urlencode($TransType).       
             "&ExtData=".urlencode($ExtData).
             "&CardNum=".urlencode($this->prepareCCNumber($CardNum)).
             "&ExpDate=".urlencode($ExpDate).
             "&MagData=".urlencode($MagData).
             "&NameOnCard=".urlencode($NameOnCard).
             "&Amount=".urlencode($Amount).
             "&InvNum=".urlencode($InvNum).
             "&PNRef=".urlencode($PNRef).
             "&Pin=".urlencode($Pin).
             "&RegisterNum=".urlencode($RegisterNum).
             "&SureChargeAmt=".urlencode($SureChargeAmt).
             "&CashBackAmt=".urlencode($CashBackAmt);
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/ProcessDebitCard",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
  }

/**
 * Process ePayment EBT Card Transactions. Valid input values are: UserName
 * & Password - Assigned by the payment gateway, <BR>TransType - FoodStampSale
 * | FoodStampReturn | CashBenefitSale | Capture | CaptureAll, <BR>CardNum
 * - Payment Card Number, ExpDate - Payment Card Expiration Date in MMYY
 * format, <BR>MagData - Payment Card Track II Mag-Stripe Data, NameOnCard
 * - Cardholders Name, Amount - Amount in DDDDD.CC format, <BR>Pin -
 * Pin Returned by Pin-Pad, <BR>RegisterNum - Register Number Pin-Pad
 * is Connected, <BR>SureChargeAmt - Sure Charge Amount in DDDDD.CC format,
 * <BR>CashBackAmt - Cash Back Amount in DDDDD.CC format, <BR>ExtData
 * - Extended Data in XML, Valid Values are: <BR>Timeout - Timeout Value
 * in Seconds (default=40), <BR>TrainingMode - Training Mode T or F,
 * <BR>KeySerialNumber - Key Serial Number for DUKPT<BR>
 */
  function &processEBTCard($UserName,$Password,$TransType,$CardNum,$ExpDate,$MagData,$NameOnCard,$Amount,$InvNum,$PNRef,$Pin,$RegisterNum,$SureChargeAmt,$CashBackAmt,$ExtData)
  {
       $sb = "UserName=".urlencode($UserName).
             "&Password=".urlencode($Password).
             "&TransType=".urlencode($TransType).
             "&CardNum=".urlencode($this->prepareCCNumber($CardNum)).
             "&ExpDate=".urlencode($ExpDate).
             "&MagData=".urlencode($MagData).
             "&NameOnCard=".urlencode($NameOnCard).
             "&Amount=".urlencode($Amount).
             "&InvNum=".urlencode($InvNum).
             "&PNRef=".urlencode($PNRef).
             "&Pin=".urlencode($Pin).
             "&RegisterNum=".urlencode($RegisterNum).
             "&SureChargeAmt=".urlencode($SureChargeAmt).
             "&CashBackAmt=".urlencode($CashBackAmt).
             "&ExtData=".urlencode($ExtData);
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/ProcessEBTCard",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
  }

/**
 * Process ePayment Gift Card Transaction. Valid input values are: UserName
 * & Password - Assigned by the payment gateway, <BR>TransType - Activate
 * | Deactivate | Refund | Redeem | Inquire | Reload, <BR>CardNum - Payment
 * Card Number, ExpDate - Payment Card Expiration Date in MMYY format,
 * <BR>MagData - Payment Card Track II Mag-Stripe Data, NameOnCard -
 * Cardholders Name, Amount - Amount in DDDDD.CC format, <BR>InvNum -
 * Invoice Tracking Number, PNRef - Reference Number Assigned by the
 * payment gateway, <BR>ExtData - Extended Data in XML, Valid Values
 * are: <BR>Timeout - Timeout Value in Seconds (default=40), <BR>TrainingMode
 * - Training Mode T or F, <BR>Force - Force Duplicates T or F, <BR>
 */
 function &processGiftCard($UserName,$Password,$TransType,$CardNum,$ExpDate,$MagData,$Amount,$InvNum,$PNRef,$ExtData)
 {
        $sb = "UserName=".urlencode($UserName).
             "&Password=".urlencode($Password).
             "&TransType=".urlencode($TransType).
             "&CardNum=".urlencode($this->prepareCCNumber($CardNum)).
             "&ExpDate=".urlencode($ExpDate).
             "&MagData=".urlencode($MagData).
             "&Amount=".urlencode($Amount).
             "&InvNum=".urlencode($InvNum).
             "&PNRef=".urlencode($PNRef).
             "&ExtData=".urlencode($ExtData);
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/ProcessGiftCard",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
 }

/**
 * Process ePayment Check Transactions. Valid input values are: UserName
 * & Password - Assigned by the payment gateway, <BR>TransType - Auth
 * | Sale | Return | Force | Void | Capture | CaptureAll, <BR>CheckNum
 * - Check Number, TransitNum - Transit NUmber <BR>AccountNum - AccountNumber,
 * <BR>Amount - Amount in DDDDD.CC format, <BR>MICR - MICR, <BR>NameOnCheck
 * - NameOnCheck, <BR>DL - Drivers License, <BR>SS - Social Security,
 * <BR>StateCode - State Code of the Driver License, <BR>CheckType -
 * CheckType (Personal | Corporate | Government), <BR>ExtData - Extended
 * Data in XML, Valid Values are: <BR>Timeout - Timeout Value in Seconds
 * (default=40), <BR>PNRef - Reference Number Assigned by the payment
 * gateway, <BR>Phone - Phone Number, <BR>EMail - E-Mail Address, <BR>RawMICR
 * - Check RawMICR Data, <BR>InvNum - Invoice Number, <BR>TrainingMode
 * - Training Mode T or F, <BR>AccountType - Account Type (Saving | Checking),
 * <BR>CityOfAccount - City where the bank account is located, <BR>BillToStreet
 * - Street address of the billing address, <BR>BillToCity - City of
 * the billing address, <BR>BillToState - State/Province of the billing
 * address, <BR>BillToPostalCode - Zip/Postal Code of the billing address,
 * <BR>BillToCountry - Country of the billing address<BR>
 */
 function &processCheck($UserName,$Password,$TransType,$CheckNum,$TransitNum,$AccountNum,$Amount,$MICR,$NameOnCheck,$DL,$SS,$DOB,$StateCode,$CheckType,$ExtData)
 {
        $sb = "UserName=".urlencode($UserName).
             "&Password=".urlencode($Password).
             "&TransType=".urlencode($TransType).
             "&CheckNum=".urlencode($this->prepareCCNumber($CardNum)).
             "&TransitNum=".urlencode($TransitNum).
             "&AccountNum=".urlencode($AccountNum).
             "&Amount=".urlencode($Amount).
             "&MICR=".urlencode($MICR).
             "&NameOnCheck=".urlencode($NameOnCheck).
             "&DL=".urlencode($DL).
             "&SS=".urlencode($SS).
             "&DOB=".urlencode($DOB).
             "&StateCode=".urlencode($StateCode).
             "&CheckType=".urlencode($CheckType).
             "&ExtData=".urlencode($ExtData);
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/ProcessCheck",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
 }

/**
 * Retrieves information from the Web Service. Valid input values are:
 * UserName & Password - Assigned by the payment gateway, TransType -
 * Initialize | Setup | BatchInquiry | StatusCheck,  <BR>ExtData - Extended
 * Data in XML, Valid Values are: <BR>TrainingMode - Training Mode T
 * or F<BR>
 */
 function &getInfo($UserName,$Password,$TransType,$ExtData)
 {
       $sb = "UserName=".urlencode($UserName).
             "&Password=".urlencode($Password).
             "&TransType=".urlencode($TransType).
             "&ExtData=".urlencode($ExtData);
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/GetInfo",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
 }

/**
 * Process Signature Transaction. <BR>Valid input values are: UserName
 * & Password - Assigned by the payment gateway<BR>SignatureType - Signature1
 * for Lipman credit, Signature2 for Lipman Check, Signature3 for AppForge,
 * Signature4 for app other than AppForge, Receipt1 for TIFF file<BR>SignatureData
 * - an array of coordinate in the following format: x1,y1^x2,y2^x3,y3^...xn,yn^~<BR>Use
 * 0,65535 as the x,y coordinate for any pen-up event.<BR>ExtData - Extended
 * Data in XML, Valid Values are: <BR>TrainingMode - Training Mode T
 * or F<BR>
 */
 function &processSignature($UserName,$Password,$SignatureType,$SignatureData,$PNRef,$Result,$AuthCode,$ExtData)
 {
         $sb = "UserName=".urlencode($UserName).
               "&Password=".urlencode($Password).
               "&SignatureType=".urlencode($SignatureType).
               "&SignatureData=".urlencode($SignatureData).
               "&PNRef=".urlencode($PNRef).
               "&Result=".urlencode($Result).
               "&AuthCode=".urlencode($AuthCode).
               "&ExtData=".urlencode($ExtData);
       $util = new Util();      
       $responseData = $util->sendHttpPost($this->url."/ProcessSignature",$sb,$this->verbose);
       $response     =& new Response($responseData,$sb);
       return $response;
 }
}
?>
